<?php

namespace App\Providers;

use App\Services\TestService;
use Illuminate\Support\ServiceProvider;

class TestServiceProvider extends ServiceProvider
{
    /**
     * Register services.
     *
     * @return void
     */
    public function register()
    {
        //使用singleton绑定单例
        $this->app->singleton('test',function(){
            return new TestService();
        });
        //controller控制器使用
        //$test = App::make('test');
        //$test->callMe('TestController1');

        /////////////////////////////////////////////////////////////////////////////
        //使用bind绑定实例到接口以便依赖注入
        //controller控制器使用
        $this->app->bind('App\Contracts\TestContract',function(){
            return new TestService();
        });
        //controller使用来实现
        //public function __construct(TestContract $test){
        //    $this->test = $test;
        //}
        //public function test1(){
        //    $this->test->callMe('TestController');
        //}
    }

    /**
     * Bootstrap services.
     *
     * @return void
     */
    public function boot()
    {
        //
    }
}
